package ranks.types;

import java.util.HashMap;
import java.util.Map;

public class Player {

	private String name;
	private Team team;
	private Position position;
	private Map<String, Integer> rankings;
	
	public static Map<String, Player> ALL_PLAYERS
		= new HashMap<String, Player>();
		
	public Player(String name, Team team, Position position) {
		this.name = name;
		this.team = team;
		this.position = position;
		
		rankings = new HashMap<String, Integer>();
	}
	
	public void setRanking(String source, Integer rank) {
		this.rankings.put(source, rank);
	}

	public String getPlayerKey() {
		StringBuffer buffer = new StringBuffer();
		
		buffer.append(name);
		buffer.append(":");
		buffer.append(team.getShortA());
		buffer.append("/");
		buffer.append(team.getShortB());
		
		return buffer.toString();
	}

	public String getName() {
		return name;
	}

	public Team getTeam() {
		return team;
	}

	public Position getPosition() {
		return position;
	}
	
	public Integer getRanking(String rankingSource) {
		return this.rankings.get(rankingSource);
	}
	
	public Map<String, Integer> getAllRankings() {
		return this.rankings;
	}
	
	public String getRankString() {
		StringBuffer buffer = new StringBuffer();
		
		for(Map.Entry<String, Integer> rank : this.rankings.entrySet()) {
			buffer.append("[" + rank.getKey());
			buffer.append("=" + rank.getValue());
			buffer.append("]");
			buffer.append(", ");
		}
		
		String rankString = buffer.toString();
		
		return rankString.substring(0, rankString.length() - 2);
	}
	
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		
		buffer.append(this.name);
		buffer.append(" (");
		buffer.append(this.team.getShortA());
		buffer.append(" - ");
		buffer.append(this.position.getPositionID());
		buffer.append(")");
		
		return buffer.toString();
	}
	
}
